using System.Collections;
using UnityEngine;

public class SaveBCWStorage : MonoBehaviour
{
	public static SaveBCWStorage instance;

	public static bool canOpenNextLevel;

	private void Awake()
	{
		if (instance != null && instance != this)
		{
			Object.Destroy(base.gameObject);
			return;
		}
		instance = this;
		Object.DontDestroyOnLoad(base.gameObject);
	}

	private void OnDestroy()
	{
		BCWDebug.Log("OnDestroy SaveBCWStorage \n" + StackTraceUtility.ExtractStackTrace());
	}

	public static void Init()
	{
		if (instance == null)
		{
			GameObject gameObject = Object.Instantiate(new GameObject());
			gameObject.AddComponent<SaveBCWStorage>();
			instance = gameObject.GetComponent<SaveBCWStorage>();
			gameObject.name = "SaveBCWStorage";
		}
	}

	public void StartSaveKeys(int sizeArray)
	{
		if (sizeArray == 0)
		{
			canOpenNextLevel = true;
		}
		else
		{
			CoroutineRunner.Instance.StartCoroutine(SaveOneKeyPerSecond(sizeArray));
		}
	}

	public IEnumerator SaveOneKeyPerSecond(int sizeArray)
	{
		canOpenNextLevel = false;
		for (int i = 0; i < sizeArray; i++)
		{
			BCWStorage.SaveAllByFrame(i);
			yield return null;
		}
		canOpenNextLevel = true;
		yield return null;
	}
}
